using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameManager : MonoBehaviour
{
    public GameObject Player;
    public float Speed;
    public Animator Anim;
    public int JumpSpeed;
    public float waitTime;
    public void Move(float v)
    {
        if (v*Speed>0)
        {
            gameObject.transform.Translate(new Vector3(v * Speed, 0, 0));
        }
        else if(v*Speed<0)
        {
            gameObject.transform.Translate(new Vector3(-v * Speed, 0, 0));
        }
           
    }  
    public void Update()
    {
        float v = Input.GetAxis("Horizontal");
        
        Move(v);
        Animating(v);
        PlayerRotation();
        Jump(v);
        Attack();
    }
    void Animating(float v)
    {
        bool walking = v != 0f;
        Anim.SetBool("isWalking", walking);
    }
    public void PlayerRotation()
    {
        if (Input.GetKey(KeyCode.A))
        {
            gameObject.transform.localRotation = Quaternion.Euler(0, 180, 0);
        }
        if (Input.GetKey(KeyCode.D))
        {
            gameObject.transform.localRotation = Quaternion.Euler(0, 0, 0);
        }
    }

    public void Jump(float v)
    {
        Rigidbody2D rg = Player.GetComponent<Rigidbody2D>();
        bool Jump = Player.transform.position.y <= 0.09;
        
        if (Input.GetKey(KeyCode.Space))
        {
            Anim.SetBool("isJumping", Jump);
            rg.velocity = new Vector2(Speed * v, JumpSpeed);
        }

        if (Jump == false)
        {
            Anim.Play("ldle");
        }
       
       
       
    }
    public void Attack()
    {
     
            if (Input.GetKey(KeyCode.Z))
            {
                Anim.Play("Attack");
                
            }
    }

    private void invoke(Action standing, float v)
    {
        throw new NotImplementedException();
    }

    public void Standing()
    {
        bool Attack=false;
        Anim.SetBool("isStanding", Attack);
    }
}
